package com.woniu.cinema.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.woniu.common.annotation.Log;
import com.woniu.common.core.controller.BaseController;
import com.woniu.common.core.domain.AjaxResult;
import com.woniu.common.enums.BusinessType;
import com.woniu.cinema.domain.UserWantMovie;
import com.woniu.cinema.service.UserWantMovieService;
import com.woniu.common.utils.poi.ExcelUtil;
import com.woniu.common.core.page.TableDataInfo;

/**
 * 用户想看的电影Controller
 * 
 * @author yy
 * @date 2021-04-16
 */
@RestController
@RequestMapping("/cinema/userwantmovie")
public class UserWantMovieController extends BaseController
{
    @Autowired
    private UserWantMovieService userWantMovieService;

    /**
     * 查询用户想看的电影列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserWantMovie userWantMovie)
    {
        startPage();
        List<UserWantMovie> list = userWantMovieService.selectUserWantMovieList(userWantMovie);
        return getDataTable(list);
    }

    /**
     * 导出用户想看的电影列表
     */
    @Log(title = "用户想看的电影", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserWantMovie userWantMovie)
    {
        List<UserWantMovie> list = userWantMovieService.selectUserWantMovieList(userWantMovie);
        ExcelUtil<UserWantMovie> util = new ExcelUtil<UserWantMovie>(UserWantMovie.class);
        return util.exportExcel(list, "userwantmovie");
    }

    /**
     * 获取用户想看的电影详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userWantMovieService.selectUserWantMovieById(id));
    }

    /**
     * 新增用户想看的电影
     */
    @Log(title = "用户想看的电影", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserWantMovie userWantMovie)
    {
        userWantMovieService.insertUserWantMovie(userWantMovie);
        AjaxResult ajaxResult = AjaxResult.success();
        ajaxResult.put("wantId",userWantMovie.getId());
        return ajaxResult;
    }

    /**
     * 修改用户想看的电影
     */
    @Log(title = "用户想看的电影", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserWantMovie userWantMovie)
    {
        return toAjax(userWantMovieService.updateUserWantMovie(userWantMovie));
    }

    /**
     * 删除用户想看的电影
     */
    @Log(title = "用户想看的电影", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userWantMovieService.deleteUserWantMovieByIds(ids));
    }
}
